package com.demo.sort.base;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.function.Function;

/**
 * @author huangChao
 **/
public abstract class SortBase {

    public int[] init() {
        return new int[]{5, 6, 94, 52, 15, 3, 14, 5, 6};
        // return new int[]{1, 3, 2, 7, 5, 6, 7, 8, 9};
    }

    public void valid(int[] validArr, int[] ints) {
        Assertions.assertArrayEquals(validArr, ints);
    }

    public void handler(Function<int[], int[]> consumer) {
        int[] init = init();
        int[] validArr = Arrays.copyOf(init, init.length);
        Arrays.sort(validArr);
        valid(consumer.apply(init), validArr);
    }

    public void swap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

    public abstract int[] sort(int[] init);

    @Test
    public void app() throws Exception {
        handler(this::sort);
    }
}
